package com.sidianzhong.sdz.service.impl;

import com.github.pagehelper.PageHelper;
import com.sidianzhong.sdz.mapper.*;
import com.sidianzhong.sdz.model.*;
import com.sidianzhong.sdz.service.*;
import com.sidianzhong.sdz.utils.PageInfo;
import com.sidianzhong.sdz.utils.Tools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;


/**
* Created by hxgqh on 2016/1/7.
*/
@Service
@Transactional
public class WebEquipmentgroupServiceImpl implements WebEquipmentgroupService{
    protected static final Logger LOG = LoggerFactory.getLogger(WebEquipmentgroupServiceImpl.class);

    // 将所有的modelMapper注入
    @Autowired
    private WebEquipmentgroupMapper webEquipmentgroupMapper;


    @Override
    public WebEquipmentgroup create(WebEquipmentgroup item) {

         webEquipmentgroupMapper.insert(item);
         return item;
    }

    @Override
    public int delete(Integer id) {
        return webEquipmentgroupMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(WebEquipmentgroup item) {

        return webEquipmentgroupMapper.updateByPrimaryKeySelective(item);
    }

    @Override
    public WebEquipmentgroup get(Integer id) {
        return webEquipmentgroupMapper.selectByPrimaryKey(id);
    }
    @Override
     public PageInfo<WebEquipmentgroup> getListWithPaging(Integer pageNum, Integer pageSize,
                                                  String sortItem, String sortOrder,WebEquipmentgroup item){

        WebEquipmentgroupExample  example = new WebEquipmentgroupExample();
        WebEquipmentgroupExample.Criteria criteria = example.createCriteria();
        if(item.getSitename() != null ){
            criteria.andSitenameEqualTo(item.getSitename());
        }
        if(item.getEquipmentname() != null ){
            criteria.andEquipmentnameEqualTo(item.getEquipmentname());
        }
        if(item.getEquipmentkey() != null ){
            criteria.andEquipmentkeyEqualTo(item.getEquipmentkey());
        }
        if(item.getTablename() != null ){
            criteria.andTablenameEqualTo(item.getTablename());
        }
        if(item.getItemname() != null ){
            criteria.andItemnameEqualTo(item.getItemname());
        }
        if(item.getImgpath() != null ){
            criteria.andImgpathEqualTo(item.getImgpath());
        }
        if(item.getAddtime() != null ){
            criteria.andAddtimeEqualTo(item.getAddtime());
        }
        if(item.getAddnamer() != null ){
            criteria.andAddnamerEqualTo(item.getAddnamer());
        }
        ArrayList<Integer> objects = new ArrayList<>();
        objects.add(8);
        objects.add(21);
        objects.add(30);
        criteria.andIdIn(objects);
        example.setOrderByClause(Tools.humpToLine(sortItem)+" "+sortOrder);
        PageHelper.startPage(pageNum, pageSize);
        List< WebEquipmentgroup> list = this.webEquipmentgroupMapper.selectByExample(example);
        PageInfo result = new PageInfo(list);

        return result;

     }

    @Override
    public WebEquipmentgroup getBykey(String equipmentkey) {
        return this.webEquipmentgroupMapper.getBykey(equipmentkey);

    }

    @Override
    public List<WebEquipmentgroup> getList() {
        WebEquipmentgroupExample  example = new WebEquipmentgroupExample();
        WebEquipmentgroupExample.Criteria criteria = example.createCriteria();
        ArrayList<Integer> objects = new ArrayList<>();
        objects.add(8);
        objects.add(21);
        objects.add(30);
        criteria.andIdIn(objects);
        List< WebEquipmentgroup> list = this.webEquipmentgroupMapper.selectByExample(example);
        return list;
    }

}
